package com.lz.football.module.mail.item
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.liangzhong.events.MailEvent;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.goods.vo.GoodsVo;
	import com.liangzhong.model.mail.MailVo;
	import com.liangzhong.model.type.MailType;
	import com.lz.football.module.base.IComponent;
	
	import common.item.ComGoodsItem;
	
	import flash.display.Bitmap;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import lz.controls.LItem;

	/**
	 *邮件条目 
	 * @author lake
	 * 
	 */	
	public class MailItem extends LItem implements IComponent
	{
		/**
		 *描述 
		 */		
		private var txtDesc 	:TextField;
		/**
		 *领取按钮 
		 */		
		private var getBtn		:SimpleButton;
		/**
		 *时间 
		 */		
		private var txtDate	:TextField;
		/**
		 *图标元件 
		 */		
		private var iconMc		:MovieClip;
		
		public function MailItem()
		{
			super();
		}
		/**
		 *设置获取数据 
		 * @param value
		 * 
		 */		
		override public function set data(value:*):void
		{
			super.data = value;
			var vo :MailVo = value;
			txtDesc.htmlText = vo.desc;
			iconMc.gotoAndStop(vo.ntype);
			if(vo.bget == 2 && vo.ntype == MailType.AWARD)//有未领
			{
				getBtn.visible = true;
				getBtn.mouseEnabled = true;
				var goods :GoodsVo = AppData.getInstance().goodsManager.getGoodsByTypeAndId(vo.value1,vo.value2);
				if(goods && iconMc.mc)
				{
					var comItem :ComGoodsItem = new ComGoodsItem();
					comItem.initUI();
					comItem.data = goods;
					DisplayObjectUtil.removeAllChildren(iconMc.mc);
					iconMc.mc.addChild(comItem);
					comItem.x = -1;
					comItem.y = -1;
				}
			}
			else
			{
				getBtn.visible = false;
			}
			txtDate.htmlText = vo.timeStr;
			resizeContent();
		}
		override public function get data():*
		{
			return super.data;
		}
		/**
		 *初始化 
		 * @param view
		 * 
		 */		
		public function initUI(view:Object=null):void
		{
			_symbolSkin = Reflection.createInstance("com.football.module.mail.ItemSkin");
			if(_symbolSkin == null)
			{
				return;
			}
			txtDesc = _symbolSkin.txtDesc;
			getBtn = _symbolSkin.getBtn;
			txtDate = _symbolSkin.txtDate;
			iconMc = _symbolSkin.iconMc;
			//iconMc.mouseChildren = false;
			//iconMc.mouseEnabled = false;
			txtDesc.selectable = false;
			txtDesc.mouseEnabled = false;
			getBtn.visible = false;
			this.addChild(_symbolSkin);
			addEvtListener();
			resizeContent();
		}
		/**
		 *重新排布内容 
		 */		
		private function resizeContent():void
		{
			txtDesc.height = txtDesc.textHeight + 5;
			txtDesc.y = (this.height - txtDesc.height)/2;
			if(getBtn.visible == false)
			{
				txtDate.y = (this.height - txtDate.height)/2;
			}
			else
			{
				txtDate.y = 37;
			}
		}
		/**
		 *添加事件 
		 * 
		 */		
		public function addEvtListener():void
		{
			getBtn.addEventListener(MouseEvent.CLICK,getGoodsHandler);
		}
		/**
		 *获取物品 
		 * @param e
		 * 
		 */		
		private function getGoodsHandler(e :MouseEvent):void
		{
			this.dispatchEvent(new MailEvent(MailEvent.GETGOODS,_data.mailid,true));
			getBtn.mouseEnabled = false;
		}
		/**
		 *删除事件 
		 * 
		 */		
		public function removeEvtListener():void
		{
			getBtn.removeEventListener(MouseEvent.CLICK,getGoodsHandler);
		}
		/**
		 *销毁 
		 * 
		 */		
		public function destroyView():void
		{
			removeEvtListener();
		}
	}
}